﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Ecreate.Web.pages
{
    public partial class NewsList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //<ul class="newslist"><li><a title="新闻标题" href="../pages/NewsPage.aspx?id={0}">新闻标题</a></li></ul>
            //<li><a title="新闻标题" href="../pages/NewsPage.aspx?id={0}">新闻标题</a></li>
            string ul = "<ul>{0}</ul>";
            string li = "<li class=\"blue\"><a title=\"{0}\" href=\"../pages/NewsList.aspx?id={1}\" target=\"_self\">{0}</a></li>";
            //0:新闻标题;1:id
            string sql = "select * from t_company_news";
            System.Data.DataTable dt = usercontrol.GG.GetTable(sql);
            string items = "";
            foreach (System.Data.DataRow dr in dt.Rows)
            {
                string s0 = dr["news_title"].ToString();
                string s1 = dr["id"].ToString();
                items += string.Format(li, new string[] { s0, s1 });
            }
            Literal1.Text = string.Format(ul, new string[] { items });
            if (Request.QueryString["id"] != null)
            {
                string id = Request.QueryString["id"].ToString();
                BindNews(id);
            }
        }

        private void BindNews(string id)
        {
            string sql = "select * from t_company_news where id=" + id;
            System.Data.DataTable dt = usercontrol.GG.GetTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                System.Data.DataRow dr = dt.Rows[0];
                txtContent.Text = dr["news_content"].ToString();
                lblTitle.Text = dr["news_title"].ToString();
                lblDate.Text = dr["news_date"].ToString();
            }
        }
    }
}
